package com.zhenwei.zscm.repo;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhenwei.zscm.common.utils.Linq;
import com.zhenwei.zscm.entity.VOrderStatisticByDateEntity;
import com.zhenwei.zscm.mapper.IOrderStatisticByDateMapper;
import com.zhenwei.zscm.mappings.OrderMapping;
import com.zhenwei.zscm.model.dto.order.OrderStatisticByDateDTO;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class OrderStatisticByDateRepo extends ServiceImpl<IOrderStatisticByDateMapper, VOrderStatisticByDateEntity> {

    public List<OrderStatisticByDateDTO> dateOrderStatistic(Date startDate, Date endDate) {
        var q = new LambdaQueryWrapper<VOrderStatisticByDateEntity>()
                .ge(startDate != null, VOrderStatisticByDateEntity::getDate, startDate)
                .le(endDate != null, VOrderStatisticByDateEntity::getDate, endDate);
        List<VOrderStatisticByDateEntity> list = list(q);
        return Linq.mapList(list, OrderMapping.INSTANCE::entity2Dto);
    }
}
